<?php
/**
 * tinymvc超轻量级PHP开发框架
 *
 * @author    Lansn
 * @copyright Copyright (c) 2024-2025
 * @license   tinymvc 遵循Apache2开源协议发布，需保留开发者信息。
 * @link      http://173654757.xyz
 */

namespace system\core;  
  
class Response extends \flight\net\Response  
{  
    /**  
     * 发送 JSON 响应  
     */  
    public function json(array $data, int $status = 200): self  
    {  
        $this->status($status)  
             ->header('Content-Type', 'application/json')  
             ->write(json_encode($data));  
        return $this;  
    }  
      
    /**  
     * 发送成功响应  
     */  
    public function success(string $message = 'Success', array $data = []): self  
    {  
        return $this->json([  
            'status' => 'success',  
            'message' => $message,  
            'data' => $data  
        ]);  
    }  
      
    /**  
     * 发送错误响应  
     */  
    public function error(string $message = 'Error', int $status = 400): self  
    {  
        return $this->json([  
            'status' => 'error',  
            'message' => $message  
        ], $status);  
    }  
      
    /**  
     * 重定向到指定 URL  
     */  
    public function redirect(string $url, int $status = 302): self  
    {  
        $this->status($status)  
             ->header('Location', $url);  
        return $this;  
    } 
}